import Mock from 'mockjs'
import qs from 'qs'

// mock的配置
Mock.setup({
  // 随机延时500-1000毫秒 模拟网络延迟
  timeout: '500-1000'
})

Mock.mock(/\/home\/new/, 'get', () => {
  return {
    code: '1',
    msg: '操作成功',
    result: [
      {
        id: '4008506',
        name: '平步青云财神家居摆件',
        desc: '艺术家瞿广慈作品，手绘上色，礼盒包装',
        price: '646.00',
        picture: 'https://yanxuan-item.nosdn.127.net/9d5d0083264344b5d85acde13570d025.jpg',
        discount: null,
        orderNum: 60
      },
      {
        id: '3996270',
        name: '超能装多功能出行胸包',
        desc: '小身材，大容量，时尚出行',
        price: '49.00',
        picture: 'https://yanxuan-item.nosdn.127.net/59b98ddea6422e71de8cec507865984f.png',
        discount: null,
        orderNum: 15
      },
      {
        id: '4000464',
        name: '趣玩奶酪纯PC拉链拉杆箱（14/20/24/26寸）',
        desc: '萌趣外形，实用功能，开启愉快旅程',
        price: '199.00',
        picture: 'https://yanxuan-item.nosdn.127.net/ee5ae3974a18a93f3f4704fe70075e10.png',
        discount: null,
        orderNum: 38
      },
      {
        id: '3997974',
        name: '入门首选，语音播报电子血压计',
        desc: '全程语音指导，一键测量，监测心率，贴心守护爸妈健康',
        price: '109.00',
        picture: 'https://yanxuan-item.nosdn.127.net/8f0c15f981c5cbcb1aa17215a259fa62.png',
        discount: null,
        orderNum: 17
      }
    ]
  }
})

Mock.mock(/\/my\/test/, 'get', () => {
  const arr = []
  for (let i = 0; i <= 5; i++) {
    arr.push(
      Mock.mock({
        id: '@id',
        name: '@ctitle(2,4)',
        image: '@image(200x200)'
      }))
  }
  return {
    msg: '请求测试接口成功',
    result: arr
  }
})

// 模拟 我的收藏
Mock.mock(/\/member\/collect/, 'get', config => {
  const queryString = config.url.split('?')[1]
  const queryObject = qs.parse(queryString)
  const items = []
  for (let i = 0; i < +queryObject.pageSize; i++) {
    items.push(Mock.mock({
      id: '@id',
      name: '@ctitle(10,20)',
      desc: '@ctitle(4,10)',
      price: '@float(100,200,2,2)',
      // http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_7.jpg
      picture: `http://zhoushugang.gitee.io/erabbit-client-pc-static/uploads/clothes_goods_${Mock.mock('@integer(1,8)')}.jpg`
    }))
  }
  return {
    msg: '获取收藏商品成功',
    result: {
      counts: 35,
      pageSize: +queryObject.pageSize,
      page: +queryObject.page,
      items
    }
  }
})
